﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.Security;

public partial class _10_Security_guest_register : System.Web.UI.Page
{
    String OWNER = "SLP2";
    String FROM_MAIL = "qooliliyahoo.com.tw@gmail.com";
    String BLANK = " ";
    String DOUBLE_TAB = "\n\n";

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        Roles.AddUserToRole(CreateUserWizard1.UserName, "staff");

        Session["user"] = User.Identity.Name;
        Session.Timeout = 10;

        MailWebService.Mail mail = new MailWebService.Mail();

        mail.sender = FROM_MAIL;
        mail.receiver = CreateUserWizard1.Email.ToString();
        mail.subject = "恭喜您完成註冊" + BLANK + OWNER;
        mail.message = "恭喜您完成註冊" + BLANK + "請熟記您的帳號與密碼" + BLANK + "如遺忘請至忘記密碼查詢" + DOUBLE_TAB
                        + "您的帳號" + BLANK + CreateUserWizard1.UserName.ToString() + DOUBLE_TAB
                        + "您的密碼" + BLANK + CreateUserWizard1.Password.ToString();

        MailWebService.WebService mailWebService = new MailWebService.WebService();
        mailWebService.sendMail(mail);

        Session["time"] = DateTimeOffset.Now;
        Session["userId"] = CreateUserWizard1.UserName.ToString();
    }
}